$(document).ready(function(){
	$(".ratebar div[class*='vote']").click(function(){
		if($(this).css("opacity") == 1)
		{
			var status = $(this).attr("class").replace("vote", "").replace(" button_disabled", "");
			var opposite = (status == "up")?"downvote":"upvote";
			var element = this;
			if((status == "up" || "down") && status != "score")
			{
				$.ajax({
					type:"POST",
					url:"js/php_scripts/votecounter.php",
					data: {"rate" : status, "id" : $(this).attr('id')},
					success: function(data) {
						if(data != "")
						{
							$(element).fadeTo('slow', 0.4);
							var divParent = $(element).parent().parent();
							(divParent.find(".score span").fadeOut("slow", function(){
								divParent.find(".score span").html(data);
								divParent.find(".score span").fadeIn("slow");
								divParent.find("."+opposite).fadeTo("slow", 1);
							}));
						}
					}
				});
			}
		}
	});
});